<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: select2-css"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-leave-add" style="display: none;">
        <input name="users" type="hidden"/>
        <div class="form-group">
            <div class="col-sm-8">
                <select class="form-control m-b select2-multiple" id="selectUsers" multiple>
                    </optgroup>
                    <optgroup th:each="users: ${usersByGroup}" th:label="'❤️❤️' + ${users['key']} + '❤️❤️'">
                        <option th:each="user: ${users['value']}" th:text="${user.firstName}"
                                th:value="${user.id}"></option>
                    </optgroup>
                </select>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: datetimepicker-js"/>
<th:block th:include="include :: select2-js"/>
<script th:inline="javascript">
    var prefix = ctx + "leaveCounterSign";

    // 防止 select2 渲染延迟
    setTimeout(function () {
        $('#form-leave-add').css('display', '');
    }, 100);

    $("#form-leave-add").validate({
        focusCleanup: true
    });

    function submitHandler() {
        var users = $('#selectUsers').select2('val');
        $.modal.confirm("确认要提交申请吗?", function () {
            var id = [[${id}]];
            var url = prefix + "/submitApply";
            var data = {
                "id": id,
                "users": users
            };
            $.operate.submit(url, "post", "json", data, refreshParentPageTable);
            $.modal.close();        // 关闭弹窗
            // $.table.refresh();      // 刷新表格
        });
    }

    // 请求结束后回调刷新父页面的表格
    function refreshParentPageTable() {
        window.parent.$.table.refresh();
    }

</script>
</body>
</html>
